#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>


extern struct bus_type mybus;   //引入外部定义的总线类型mybus


int myprobe (struct device *dev)
{
    printk(KERN_EMERG " this is mybus driver probe!\n");
    return 0;
}


int myremove (struct device *dev)
{
    printk(KERN_EMERG " this is mybus driver remove!\n");
    return 0;
}

struct device_driver mydriver = {
    .name = "mydevice",         // 驱动程序的名称
    .bus = &mybus,              // 驱动程序所属总线
    .probe = myprobe,           // 驱动 探测函数
    .remove = myremove,         // 驱动 移除函数
};



static int __init mydriver_init(void)
{   
    int ret;
   
    // 注册 驱动
    ret = driver_register(&mydriver);
    if (ret < 0)
    {
        printk(KERN_EMERG "mydriver_init error!\n");

        return ret;
    }

    printk(KERN_EMERG "mydevice_init OK!\n");
    return 0;
}

static void __exit mydriver_exit(void)
{
    // 注销驱动
    driver_unregister(&mydriver);
    printk(KERN_EMERG "mydriver_exit OK!\n");  
}



module_init(mydriver_init);
module_exit(mydriver_exit);

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Treasure1029");


